package com.weixing.mall.provider.controller.ads;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.model.dto.ads.MediaLableDto;
import com.weixing.mall.provider.model.query.MediaLableQuery;
import com.weixing.mall.provider.service.IMediaLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName MediaLableController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/8/15
 * @Version 1.0
 **/
@RestController
@RequestMapping("mediaLable")
@Api(value = "媒体标签APi", tags = "媒体标签")
public class MediaLabelController extends BaseController {

    @Autowired
    private IMediaLabelService mediaLabelService;

    @ApiOperation(value = "加载媒体标签列表")
    @GetMapping("")
    public Result list(MediaLableQuery mediaLableQuery){
        return ResultUtil.success(mediaLabelService.selectOfPage(initMpPage(),mediaLableQuery));
    }

    @ApiOperation(value = "查询媒体标签")
    @GetMapping("getList")
    public Result getList(MediaLableQuery mediaLableQuery){
        return ResultUtil.success(mediaLabelService.getList(mediaLableQuery));
    }

    @ApiOperation(value = "查看媒体标签")
    @GetMapping("getLable/{id}")
    public Result getLable(@PathVariable long id){
        return ResultUtil.success(mediaLabelService.getById(id));
    }

    @ApiOperation(value = "保存媒体标签信息")
    @PostMapping("save")
    @NoRepeatSubmit
    public Result save(@Validated MediaLableDto mediaLableDto){
        mediaLabelService.save(mediaLableDto);
        return ResultUtil.success();
    }

    @ApiOperation(value = "删除媒体标签信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "媒体标签id", paramType = "path", dataType = "long")
    })
    @PostMapping("del/{id}")
    public Result del(@PathVariable long id) {
        return mediaLabelService.removeById(id)  ? ResultUtil.success() : ResultUtil.error();
    }

    @ApiOperation(value = "查询-用于媒体平台 select下拉框")
    @GetMapping("form")
    public Result form(){
        return ResultUtil.success(mediaLabelService.selectMediaLablList());
    }
}
